package com.example.teesystem.entity;

import com.baomidou.mybatisplus.annotation.*;

import java.io.Serializable;
import java.util.Date;

import com.example.teesystem.entity.vo.library.IssueLibraryInsertVo;
import com.example.teesystem.entity.vo.library.TipLibraryInsertVo;
import com.example.teesystem.filter.MyHandlerInterceptor;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.springframework.beans.BeanUtils;

/**
 * 
 * @TableName t_library
 */
@TableName(value ="t_library")
@Data
@AllArgsConstructor
@NoArgsConstructor
public class Library implements Serializable {
    /**
     * 
     */
    @TableId(value = "id", type = IdType.AUTO)
    private Integer id;

    /**
     * 
     */
    @TableField(value = "student_id")
    private Integer studentId;

    /**
     * 
     */
    @TableField(value = "course_id")
    private Integer courseId;

    /**
     * 
     */
    @TableField(value = "issue_id")
    private Integer issueId;

    /**
     * 
     */
    @TableField(value = "message")
    private String message;

    /**
     * 0题目收藏 1个人心得
     */
    @TableField(value = "library_type")
    private Integer libraryType;

    /**
     * 
     */
    @TableField(value = "upload_time",fill = FieldFill.INSERT)
    private Date uploadTime;

    @TableField(value = "title")
    private String title;

    /**
     * 是否删除0未删除1已删除
     */
    @TableField(value = "is_delete")
    private Integer isDelete;

    @TableField(exist = false)
    private static final long serialVersionUID = 1L;

    @Override
    public boolean equals(Object that) {
        if (this == that) {
            return true;
        }
        if (that == null) {
            return false;
        }
        if (getClass() != that.getClass()) {
            return false;
        }
        Library other = (Library) that;
        return (this.getId() == null ? other.getId() == null : this.getId().equals(other.getId()))
            && (this.getStudentId() == null ? other.getStudentId() == null : this.getStudentId().equals(other.getStudentId()))
            && (this.getCourseId() == null ? other.getCourseId() == null : this.getCourseId().equals(other.getCourseId()))
            && (this.getIssueId() == null ? other.getIssueId() == null : this.getIssueId().equals(other.getIssueId()))
            && (this.getMessage() == null ? other.getMessage() == null : this.getMessage().equals(other.getMessage()))
            && (this.getLibraryType() == null ? other.getLibraryType() == null : this.getLibraryType().equals(other.getLibraryType()))
            && (this.getUploadTime() == null ? other.getUploadTime() == null : this.getUploadTime().equals(other.getUploadTime()))
            && (this.getIsDelete() == null ? other.getIsDelete() == null : this.getIsDelete().equals(other.getIsDelete()));
    }

    @Override
    public int hashCode() {
        final int prime = 31;
        int result = 1;
        result = prime * result + ((getId() == null) ? 0 : getId().hashCode());
        result = prime * result + ((getStudentId() == null) ? 0 : getStudentId().hashCode());
        result = prime * result + ((getCourseId() == null) ? 0 : getCourseId().hashCode());
        result = prime * result + ((getIssueId() == null) ? 0 : getIssueId().hashCode());
        result = prime * result + ((getMessage() == null) ? 0 : getMessage().hashCode());
        result = prime * result + ((getLibraryType() == null) ? 0 : getLibraryType().hashCode());
        result = prime * result + ((getUploadTime() == null) ? 0 : getUploadTime().hashCode());
        result = prime * result + ((getIsDelete() == null) ? 0 : getIsDelete().hashCode());
        return result;
    }

    @Override
    public String toString() {
        StringBuilder sb = new StringBuilder();
        sb.append(getClass().getSimpleName());
        sb.append(" [");
        sb.append("Hash = ").append(hashCode());
        sb.append(", id=").append(id);
        sb.append(", studentId=").append(studentId);
        sb.append(", courseId=").append(courseId);
        sb.append(", issueId=").append(issueId);
        sb.append(", message=").append(message);
        sb.append(", libraryType=").append(libraryType);
        sb.append(", uploadTime=").append(uploadTime);
        sb.append(", isDelete=").append(isDelete);
        sb.append(", serialVersionUID=").append(serialVersionUID);
        sb.append("]");
        return sb.toString();
    }

    public Library(IssueLibraryInsertVo issueLibraryInsertVo){
        BeanUtils.copyProperties(issueLibraryInsertVo, this);
        this.libraryType = 0;
        this.studentId = MyHandlerInterceptor.getUid();
    }

    public Library(TipLibraryInsertVo tipLibraryInsertVo){
        BeanUtils.copyProperties(tipLibraryInsertVo, this);
        this.libraryType = 1;
        this.studentId = MyHandlerInterceptor.getUid();
    }
}